home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Development Tools & Languages / DTSCPlusLibrary / Sources / Timer.cp < prev    next >
Encoding:
Text File  |  1993-01-14  |  2.5 KB  |  116 lines  |  [TEXT/MPS ]

  1. /* _________________________________________________________________________________________________________ //
  2.   Copyright © 1992-93 Apple Computer, Inc. All rights reserved.
  3.   Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
  4.   Programmer: Kent Sandvik
  5.   Date: 12/14/92
  6.   Revision comments are at the end of this file.
  7.   ---
  8.   TTimer is a simple timing class that could provide both 10 lap time values as well as
  9.   final values.
  10.   TTimer.cp contains the TTimer member functions.
  11.   _________________________________________________________________________________________________________ */
  12.  
  13. #ifndef _TIMER_
  14. #include "Timer.h"
  15. #endif
  16.  
  17.  
  18. // _________________________________________________________________________________________________________ //
  19. //    TTimer Class definitions.
  20.  
  21. //    CONSTRUCTORS AND DESTRUCTORS
  22. #pragma segment Timer
  23. TTimer::TTimer()
  24. // Default constructor.
  25. {
  26.     this->Reset();
  27. }
  28.  
  29.  
  30. #pragma segment Timer
  31. TTimer::~TTimer()
  32. // Default destructor -- empty for the time being.
  33. {
  34. }
  35.  
  36.  
  37. //    MAIN INTERFACES
  38. #pragma segment Timer
  39. void TTimer::Start()
  40. // Start the timer.
  41. {
  42.     fStartTick = ::TickCount();
  43. }
  44.  
  45.  
  46. #pragma segment Timer
  47. void TTimer::Stop()
  48. // Stop the timer.
  49. {
  50.     fStopTick = ::TickCount();
  51. }
  52.  
  53. #pragma segment Timer
  54. void TTimer::Reset()
  55. // Reset the internal count to zero.
  56. {
  57.     fStartTick = fStopTick = 0;
  58. }
  59.  
  60.  
  61. #pragma segment Timer
  62. void TTimer::SetLap(short index)
  63. // Set a lap time, where we have 10 lap registers.
  64. {
  65.     VASSERT(index < 11, ("Index is bigger than 10 = %d\n", index));
  66.     if (index < 11)
  67.         fLapIndex[index] = ::TickCount() - fStartTick;
  68. }
  69.  
  70.  
  71. #pragma segment Timer
  72. long TTimer::GetLap(short index)
  73. // Get the lap time, we have 10 lap registers.
  74. {
  75.     VASSERT(index < 11, ("Index is bigger than 10 = %d\n", index));
  76.     if (index < 11)
  77.         return fLapIndex[index];
  78.     else
  79.         return 0;
  80. }
  81.  
  82.  
  83. #pragma segment Timer
  84. long TTimer::GetLap()
  85. // Get a temporary lap time, independent of the registers.
  86. {
  87.     long temp = ::TickCount();
  88.     return (temp - fStartTick);
  89. }
  90.  
  91.  
  92. #pragma segment Timer
  93. long TTimer::GetTicks()
  94. // Get tick count from when we started the timer.
  95. {
  96.     return (fStopTick - fStartTick);
  97. }
  98.  
  99.  
  100. #pragma segment Timer
  101. float TTimer::GetSeconds()
  102. // Get N seconds from the point of time when we started the timer.
  103. {
  104.     return ((float)(fStopTick - fStartTick) / 60L);
  105. }
  106.  
  107.  
  108. // _________________________________________________________________________________________________________ //
  109.  
  110.  
  111. /*    Change History (most recent last):
  112.   No        Init.    Date        Comment
  113.   1            khs        12/14/92    New file
  114.   2            khs        1/3/93        Cleanup
  115. */
  116.